#!/usr/bin/env bash
mkdir -p /var/local/jdhelper
mkdir -p /var/local/jdhelper/pro
cd  /var/local/jdhelper
touch start.sh
cat >/var/local/jdhelper/start.sh  <<EOF
#!/usr/bin/env bash
#cd /var/local/jdhelper/con
#删除容器
#docker rm -f $(docker ps -a | grep jdhelperconsumer | awk '{print $1}')
#删除镜像
#docker rmi jdhelperconsumer
#打包镜像
#docker build -t jdhelperconsumer .
#启动容器
#docker run -e TZ="Asia/Shanghai" -d --net=host  --restart=always  --name=jdhelperconsumer jdhelperconsumer
#echo "$var启动完成"
cd /var/local/jdhelper/pro
#删除容器
docker rm -f $(docker ps -a | grep jdhelperprovider | awk '{print $1}')
#删除镜像
docker rmi jdhelperprovider
#打包镜像
docker build -t jdhelperprovider .
#启动容器
docker run -e TZ="Asia/Shanghai" -d --net=host  --restart=always  --name=jdhelperprovider jdhelperprovider
echo "$var启动完成"
EOF
cd  /var/local/jdhelper/pro
touch Dockerfile
cat >/var/local/jdhelper/pro/Dockerfile  <<EOF
FROM adoptopenjdk/openjdk11:jre-11.0.8_10-alpine
ENV OPTS_PROFILES_ACTIVE="prod" \
 OPTS_JVM_OPTS="-Dserver.port=8855" \
 OPTS_ENV_MARK="none" \
 OPTS_NODE_MARK="none" \
 OPTS_OTHER=""
#ENV TZ=Asia/Shanghai
RUN set -ex \
        && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
        && echo "Asia/Shanghai" > /etc/timezone
#RUN set -eux; \ 
#        ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \
#        echo $TZ > /etc/timezone
RUN mkdir -p /data/
COPY ./JDhelperProvider-1.0.0.jar /data/app.jar
HEALTHCHECK --interval=11s --timeout=2s --retries=12 \
  CMD curl --silent --fail localhost:8855/healthz
VOLUME ["/data/logs"]
WORKDIR  /data
EXPOSE 8080 8081
CMD OPTS_NODE_MARK=`ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | awk -F: '{print $2}'` && \
    java -Dspring.profiles.active=${OPTS_PROFILES_ACTIVE} \
         -Decarx.profile.env=${OPTS_ENV_MARK} \
         -Decarx.profile.node=${OPTS_NODE_MARK} \
         ${OPTS_JVM_OPTS} \
         ${OPTS_OTHER} \
         -Djava.security.egd=file:/dev/./urandom \
         -jar /data/app.jar 
EOF
echo "成功"